package com.jielihaofeng.springboot.websocket.enums;

import java.util.Optional;
import java.util.stream.Stream;

/**
 * @description 消息类型枚举
 * @author Johnnie Wind
 * @date 2021/4/7 22:03
 */
public enum MessageType {

    // messageType 1代表上线 2代表下线 3代表在线名单 4代表普通消息
    ONLINE("上线", "1"),
    OFFLINE("下线", "2"),
    ONLINE_LIST("在线名单","3"),
    NORMAL("普通消息","4")
    ;

    private String key;
    private String value;

    public static MessageType getByValue(String value) {
        MessageType[] values = values();
        Optional<MessageType> findFirst = Stream.of(values).filter((v) -> {
            return v.getValue().equals(value);
        }).findFirst();
        return findFirst.isPresent() ? (MessageType) findFirst.get() : null;
    }

    private MessageType(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public String getKey() {
        return this.key;
    }

    public String getValue() {
        return this.value;
    }

}
